list widgets: Simplify the constructors
authorMatthias Clasen <mclasen@redhat.com>
Tue, 1 Sep 2020 16:24:06 +0000 (12:24 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 1 Sep 2020 16:24:06 +0000 (12:24 -0400)
Now that both arguments to the _new_with_factory() constructors
are nullable, there's no good reason to keep a separate _new()
around. Just make gtk_list_view_new() and gtk_grid_view_new()
take both a model and a factory.

16 files changed:
demos/gtk-demo/listview_applauncher.c
demos/gtk-demo/listview_clocks.c
demos/gtk-demo/listview_colors.c
demos/gtk-demo/listview_weather.c
demos/gtk-demo/listview_words.c
docs/reference/gtk/gtk4-sections.txt
gtk/gtkcolumnview.c
gtk/gtkcustompaperunixdialog.c
gtk/gtkgridview.c
gtk/gtkgridview.h
gtk/gtklistview.c
gtk/gtklistview.h
tests/testcolumnview.c
tests/testlistdnd.c
tests/testlistview-animating.c
tests/testlistview.c

index c52a224e2e08af90785b5f9ce87fae9b7f65da08..3dcdbca05584b4177e76484283a725cd6ac83c1d 100644 (file)
@@ -176,7 +176,7 @@ do_listview_applauncher (GtkWidget *do_widget)
 
       /* Create the list widget here.
        */
-      list = gtk_list_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
+      list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
 
       /* We connect the activate signal here. It's the function we defined
        * above for launching the selected application.
index 07332da2592967fc38d5e0715fbadc375966d219..9dbdc0d5e725b53843801d8c717cbf929168ed8c 100644 (file)
@@ -485,7 +485,7 @@ do_listview_clocks (GtkWidget *do_widget)
       g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
 
       model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_clocks_model ()));
-      gridview = gtk_grid_view_new_with_factory (model, factory);
+      gridview = gtk_grid_view_new (model, factory);
       gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
       gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
 
index 64fb6e0cb554f7fc6b7cefd4499a4cbb5fc72462..e46e7d8b3c2da6490de344c5816457268ddd3ef6 100644 (file)
@@ -663,7 +663,7 @@ create_color_grid (void)
   GtkWidget *gridview;
   GtkListItemFactory *factory;
 
-  gridview = gtk_grid_view_new (NULL);
+  gridview = gtk_grid_view_new (NULL, NULL);
   gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
   gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
 
@@ -950,7 +950,7 @@ do_listview_colors (GtkWidget *do_widget)
 
       factory = gtk_signal_list_item_factory_new ();
       g_signal_connect (factory, "setup", G_CALLBACK (setup_selection_listitem_cb), NULL);
-      selection_view = gtk_grid_view_new_with_factory (NULL, factory);
+      selection_view = gtk_grid_view_new (NULL, factory);
       gtk_widget_add_css_class (selection_view, "compact");
       gtk_grid_view_set_max_columns (GTK_GRID_VIEW (selection_view), 200);
       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), selection_view);
index 6f0f17f0a62955c39975a07a72c0327238218071..488fd24ead0475eea98caff31cd9129a804415ad 100644 (file)
@@ -288,7 +288,7 @@ create_weather_view (void)
   g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
   g_signal_connect (factory, "bind", G_CALLBACK (bind_widget), NULL);
   model = GTK_SELECTION_MODEL (gtk_no_selection_new (create_weather_model ()));
-  listview = gtk_list_view_new_with_factory (model, factory);
+  listview = gtk_list_view_new (model, factory);
   gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
   gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
 
index 8b41be795bdef5a2dc60ac551d4e22753fc18696..4932d3f9d729bdeba11440d8b42796517bb17b9b 100644 (file)
@@ -217,7 +217,7 @@ do_listview_words (GtkWidget *do_widget)
       gtk_widget_set_vexpand (sw, TRUE);
       gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
 
-      listview = gtk_list_view_new_with_factory (
+      listview = gtk_list_view_new (
           GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (filter_model))),
           gtk_builder_list_item_factory_new_from_bytes (NULL,
               g_bytes_new_static (factory_text, strlen (factory_text))));
index 1ec07553d8409e2294a18773d80bff7fadd3adc5..2565d38c43ba6f5885f1be3c6f6d624013a488b0 100644 (file)
@@ -520,7 +520,6 @@ gtk_signal_list_item_factory_get_type
 <TITLE>GtkListView</TITLE>
 GtkListView
 gtk_list_view_new
-gtk_list_view_new_with_factory
 gtk_list_view_set_factory
 gtk_list_view_get_factory
 gtk_list_view_set_model
@@ -616,7 +615,6 @@ gtk_column_view_column_get_type
 <TITLE>GtkGridView</TITLE>
 GtkGridView
 gtk_grid_view_new
-gtk_grid_view_new_with_factory
 gtk_grid_view_set_model
 gtk_grid_view_get_model
 gtk_grid_view_set_max_columns
index 48a87ea6e3a72e28bd149940bec247587ce40455..c3cb62839e6b38adbeda8c49124caaf439aa62ae 100644 (file)
@@ -1165,7 +1165,7 @@ gtk_column_view_init (GtkColumnView *self)
 
   self->sorter = gtk_column_view_sorter_new ();
   self->factory = gtk_column_list_item_factory_new (self);
-  self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (NULL,
+  self->listview = GTK_LIST_VIEW (gtk_list_view_new (NULL,
         GTK_LIST_ITEM_FACTORY (g_object_ref (self->factory))));
   gtk_widget_set_hexpand (GTK_WIDGET (self->listview), TRUE);
   gtk_widget_set_vexpand (GTK_WIDGET (self->listview), TRUE);
index 927c14f80cdd3da04dba8eba0c7833a8e02c8b33..ce282f8c321ee91ed5d2bd83a5490103f3453654 100644 (file)
@@ -901,7 +901,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
   g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
   g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
 
-  listview = gtk_list_view_new_with_factory (model, factory);
+  listview = gtk_list_view_new (model, factory);
   gtk_widget_set_size_request (listview, 140, -1);
 
   dialog->listview = listview;
index c80c60108b485a9913fc6dc9a0b8856875ee2bb2..5e3af58f5b5d9733c01e64ce8d47d35266c63313 100644 (file)
@@ -1179,51 +1179,23 @@ gtk_grid_view_init (GtkGridView *self)
 /**
  * gtk_grid_view_new:
  * @model: (allow-none) (transfer full): the model to use, or %NULL
- *
- * Creates a new #GtkGridView.
- *
- * You most likely want to call gtk_grid_view_set_factory() to
- * set up a way to map its items to widgets next.
- *
- * Returns: a new #GtkGridView
- **/
-GtkWidget *
-gtk_grid_view_new (GtkSelectionModel *model)
-{
-  GtkWidget *result;
-
-  g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
-
-  result = g_object_new (GTK_TYPE_GRID_VIEW,
-                         "model", model,
-                         NULL);
-
-  /* consume the reference */
-  g_clear_object (&model);
-
-  return result;
-}
-
-/**
- * gtk_grid_view_new_with_factory:
- * @model: (allow-none) (transfer full): the model to use, or %NULL
  * @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
  *
  * Creates a new #GtkGridView that uses the given @factory for
  * mapping items to widgets.
  *
  * The function takes ownership of the
- * argument, so you can write code like
+ * arguments, so you can write code like
  * ```
- *   grid_view = gtk_grid_view_new_with_factory (create_model (),
+ *   grid_view = gtk_grid_view_new (create_model (),
  *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
  * ```
  *
- * Returns: a new #GtkGridView using the given @factory
+ * Returns: a new #GtkGridView using the given @model and @factory
  **/
 GtkWidget *
-gtk_grid_view_new_with_factory (GtkSelectionModel  *model,
-                                GtkListItemFactory *factory)
+gtk_grid_view_new (GtkSelectionModel  *model,
+                   GtkListItemFactory *factory)
 {
   GtkWidget *result;
 
index 4dd6b067bdb4a947bc29d9c4b4e8a7b2c7d89bd2..629a8db7ffd0ef7070c5ab4e6a86779e0de2b133 100644 (file)
@@ -48,9 +48,7 @@ GDK_AVAILABLE_IN_ALL
 GType           gtk_grid_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_grid_view_new                               (GtkSelectionModel      *model);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_grid_view_new_with_factory                  (GtkSelectionModel      *model,
+GtkWidget *     gtk_grid_view_new                               (GtkSelectionModel      *model,
                                                                  GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
index 514e59538320a4b84feedc0da055c153b2c4a360..e7f2cf18bbd172df3319558a4693c047f5f2d24e 100644 (file)
  *   g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
  *   g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
  *
- *   list = gtk_list_view_new_with_factory (model, factory);
+ *   list = gtk_list_view_new (model, factory);
  *
  *   g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
  *
@@ -934,51 +934,23 @@ gtk_list_view_init (GtkListView *self)
 /**
  * gtk_list_view_new:
  * @model: (allow-none) (transfer full): the model to use, or %NULL
- *
- * Creates a new #GtkListView.
- *
- * You most likely want to call gtk_list_view_set_factory()
- * to set up a way to map its items to widgets.
- *
- * Returns: a new #GtkListView
- **/
-GtkWidget *
-gtk_list_view_new (GtkSelectionModel *model)
-{
-  GtkWidget *result;
-
-  g_return_val_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model), NULL);
-
-  result = g_object_new (GTK_TYPE_LIST_VIEW,
-                         "model", model,
-                         NULL);
-
-  /* consume the reference */
-  g_clear_object (&model);
-
-  return result;
-}
-
-/**
- * gtk_list_view_new_with_factory:
- * @model: (allow-none) (transfer full): the model to use, or %NULL
  * @factory: (allow-none) (transfer full): The factory to populate items with, or %NULL
  *
  * Creates a new #GtkListView that uses the given @factory for
  * mapping items to widgets.
  *
  * The function takes ownership of the
- * argument, so you can write code like
+ * arguments, so you can write code like
  * ```
- *   list_view = gtk_list_view_new_with_factory (create_model (),
+ *   list_view = gtk_list_view_new (create_model (),
  *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
  * ```
  *
- * Returns: a new #GtkListView using the given @factory
+ * Returns: a new #GtkListView using the given @model and @factory
  **/
 GtkWidget *
-gtk_list_view_new_with_factory (GtkSelectionModel  *model,
-                                GtkListItemFactory *factory)
+gtk_list_view_new (GtkSelectionModel  *model,
+                   GtkListItemFactory *factory)
 {
   GtkWidget *result;
 
index 43c29b0ddc0d2c06268da03eae2c66007e932292..9a258de1dabc2b77f04a3eb4f96a0ca9918a59a6 100644 (file)
@@ -47,9 +47,7 @@ GDK_AVAILABLE_IN_ALL
 GType           gtk_list_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_list_view_new                               (GtkSelectionModel      *model);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *     gtk_list_view_new_with_factory                  (GtkSelectionModel      *model,
+GtkWidget *     gtk_list_view_new                               (GtkSelectionModel      *model,
                                                                  GtkListItemFactory     *factory);
 
 GDK_AVAILABLE_IN_ALL
index 725ce67b7a9320b683767edce2b3bdf42929545b..d38e83ce6d080c98bde6c6b1f01592ec67895dda 100644 (file)
@@ -773,7 +773,7 @@ main (int argc, char *argv[])
 
   g_object_unref (filter);
 
-  list = gtk_list_view_new_with_factory (
+  list = gtk_list_view_new (
              GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (gtk_column_view_get_columns (GTK_COLUMN_VIEW (view))))),
              gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui))));
   gtk_box_append (GTK_BOX (hbox), list);
index 899ed1edc1362947e76d9d03e125865db9e23b77..803ff2164d2ff069498437ce8c6feeb0616f3381 100644 (file)
@@ -348,7 +348,7 @@ main (int argc, char *argv[])
   g_signal_connect (factory, "bind", G_CALLBACK (bind_item), NULL);
   g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), NULL);
 
-  grid = gtk_grid_view_new_with_factory (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
+  grid = gtk_grid_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
   gtk_grid_view_set_min_columns (GTK_GRID_VIEW (grid), 20);
   gtk_grid_view_set_max_columns (GTK_GRID_VIEW (grid), 20);
 
@@ -359,7 +359,7 @@ main (int argc, char *argv[])
   gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
   gtk_stack_add_titled (GTK_STACK (stack), sw, "list", "GtkListView");
 
-  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE))));
+  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_model (0, 400, 1, FALSE))), NULL);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
 
   factory = gtk_signal_list_item_factory_new ();
@@ -401,7 +401,7 @@ main (int argc, char *argv[])
   gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
   gtk_stack_add_titled (GTK_STACK (stack), sw, "tree", "Tree");
 
-  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20))));
+  list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (create_tree_model (20, 20))), NULL);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
 
   factory = gtk_signal_list_item_factory_new ();
index 70aa4a1de640bbd4981479c74e6e5ceef8d51895..33c69e356592b6c8581e4c9cf7b5e68400443675 100644 (file)
@@ -149,7 +149,7 @@ main (int   argc,
   factory = gtk_signal_list_item_factory_new ();
   g_signal_connect (factory, "setup", G_CALLBACK (setup_list_item), NULL);
   g_signal_connect (factory, "bind", G_CALLBACK (bind_list_item), NULL);
-  listview = gtk_list_view_new_with_factory (NULL, factory);
+  listview = gtk_list_view_new (NULL, factory);
 
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
 
index fcbac01e3cc1fd9ef043f5e5e065b02e091bc902..53234078b58909d5a0fc27e25d97f8fe925d7ecf 100644 (file)
@@ -615,7 +615,7 @@ main (int argc, char *argv[])
 
   factory = gtk_signal_list_item_factory_new ();
   g_signal_connect (factory, "setup", G_CALLBACK (setup_widget), NULL);
-  listview = gtk_list_view_new_with_factory (NULL, factory);
+  listview = gtk_list_view_new (NULL, factory);
   gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), listview);
 
   if (argc > 1)